﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TPOJ.IDAL;
using TPOJ.DALFactory;
using TPOJ.Model;

namespace TPOJ.BLL
{
    public class ContestBO
    {
        private static readonly IContestDAO dal = DataAccess.CreateContestDAO();

        public IList<Contest> GetContests()
        {
            return dal.GetContests();
        }

        public Contest GetContest(int id)
        {
            return dal.GetContest(id);
        }

        public IList<Standing> GetContestStanding(int id)
        {
            var standings = dal.GetContestStanding(id);
            foreach (var item in standings)
            {
                this.RefreshStanding(item.UniqueId);
            }
            return standings;
        }
        
        public IList<Contest> GetCurrentContests()
        {
            return dal.GetCurrentContests();
        }

        public Standing FindContestStanding(int contestId, int accountId)
        {
            return dal.FindContestStanding(contestId, accountId);
        }

        public Standing AddContestStanding(int contestId, int accountId)
        {
            return dal.AddContestStanding(contestId, accountId);
        }

        public StandingCell FindContestStandingCell(int standingId, int id)
        {
            return dal.FindContestStandingCell(standingId, id);
        }

        internal StandingCell AddContestStandingCell(int standingId, int cellId)
        {
            return dal.AddContestStandingCell(standingId, cellId);
        }

        internal StandingCell EditContestStandingCell(int id, int standingId, int time, int waSubmits, int submits)
        {
            return dal.EditContestStandingCell(id, standingId, time, waSubmits, submits);
        }

        internal void RefreshStanding(int standingId)
        {
            dal.RefreshStanding(standingId);
        }

        public void Create(Contest contest)
        {
            dal.Create(contest);
        }

        public void AddContestProblem(int cid, int pid)
        {
            dal.AddContestProblem(cid, pid);
        }

        public void DeleteContestProblem(int cid, int pid)
        {
            dal.DeleteContestProblem(cid, pid);
        }

        public Contest Edit(Contest contest)
        {
            return dal.Edit(contest);
        }
    }
}
